from utils import tf_metrics
import tensorflow as tf


def event_evaluate(y_true, y_pred, sess):
    pos_indices = [1, 2, 3, 4, 5, 6, 7]  # Class 0 is the 'negative' class
    num_classes = 8
    average = 'micro'
    # 以下数据的格式 Tuple of (value, update_op)
    precision = tf_metrics.precision(
        y_true, y_pred, num_classes, pos_indices, average=average)
    recall = tf_metrics.recall(
        y_true, y_pred, num_classes, pos_indices, average=average)
    f2 = tf_metrics.fbeta(
        y_true, y_pred, num_classes, pos_indices, average=average, beta=2)
    f1 = tf_metrics.f1(
        y_true, y_pred, num_classes, pos_indices, average=average)
    # Run the update op and get the updated value
    with tf.Session() as sess:
        sess.run(tf.local_variables_initializer())
        print('   p {}| r {} |f1 {}'.format(sess.run(precision[1]), sess.run(recall[1]), sess.run(f1[1])))



def role_evaluate(y_true, y_pred):
    pos_indices = [1, 2, 3, 4]  # Class 0 is the 'negative' class
    num_classes = 5
    average = 'micro'
    # 以下数据的格式 Tuple of (value, update_op)
    precision = tf_metrics.precision(
        y_true, y_pred, num_classes, pos_indices, average=average)
    recall = tf_metrics.recall(
        y_true, y_pred, num_classes, pos_indices, average=average)
    f2 = tf_metrics.fbeta(
        y_true, y_pred, num_classes, pos_indices, average=average, beta=2)
    f1 = tf_metrics.f1(
        y_true, y_pred, num_classes, pos_indices, average=average)
    # Run the update op and get the updated value
    with tf.Session() as sess:
        sess.run(tf.local_variables_initializer())
        print('   p {}| r {} |f1 {}'.format(sess.run(precision[1]), sess.run(recall[1]), sess.run(f1[1])))

